package topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import utils.RabbitMQUtils;

import java.io.IOException;

public class Provider {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = null;
        if (connection != null) {
            channel = connection.createChannel();
        }
        //通道声明交换机
        String exchangeName = "topics";
        String exchangeType = "topic";
        if (channel != null) {
            channel.exchangeDeclare(exchangeName, exchangeType);
            //发送消息
            String routingKey = "user";
            String message = "这是基于topic模型的routingkey：【"+routingKey+"】发送的消息";
            channel.basicPublish(exchangeName, routingKey, null,message.getBytes());
        }
        //关闭资源
        RabbitMQUtils.closeConnectionAndChannel(channel, connection);
    }
}
